<template>
	<view>
		<u-notify ref="uNotify"></u-notify>
		<u-picker :show="show" :columns="columns" keyName="label" @confirm="confirm" @cancel="show=false"
			:closeOnClickOverlay="true" @close="show=false"></u-picker>
		<u-picker :show="showCity" ref="uPicker" :columns="columnsCity" @confirm="confirmCity" @change="changeHandler"
			@cancel="showCity=false" :loading="lodingselect" :closeOnClickOverlay="true"
			@close="showCity=false"></u-picker>
		<view class="addForm">
			<view class="formBox">
				<u--form :model="FormData" ref="FormData" :rules="rules" labelWidth=100>
					<u-form-item @click="this.show = true" label="选择职业" prop="occupation" borderBottom>
						<u-input v-model="FormData.occupation" border="none" placeholder="请选择" inputAlign="right"
							readonly></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="姓名" prop="name" borderBottom>
						<u-input v-model="FormData.name" border="none" placeholder="请填写姓名" inputAlign="right"></u-input>
					</u-form-item>
					<u-form-item label="手机号码" prop="phoneNumber" borderBottom>
						<u-input v-model="FormData.phoneNumber" border="none" placeholder="请填写手机号" inputAlign="right"
							type="number"></u-input>
					</u-form-item>
					<u-form-item label="微信号" prop="wechatId" borderBottom>
						<u-input v-model="FormData.wechatId" border="none" placeholder="请填写微信号"
							inputAlign="right"></u-input>
					</u-form-item>
					<u-form-item @click="this.showCity = true" label="城市" prop="cityId" borderBottom>
						<u-input v-model="FormData.cityId" border="none" placeholder="请选择" inputAlign="right"
							readonly></u-input>
						<u-icon slot="right" name="arrow-right"></u-icon>
					</u-form-item>
					<u-form-item label="地区" prop="district" borderBottom>
						<u-input v-model="FormData.district" border="none" placeholder="请填写所在地区"
							inputAlign="right"></u-input>
					</u-form-item>
					<u-form-item label="证件" prop="idCard" borderBottom labelWidth=60>
						<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="6" multiple
							:maxCount="1" width="160" height="60">
							<image src="https://cdn.uviewui.com/uview/demo/upload/positive.png" mode="widthFix"
								style="width: 160px;height: 60px;"></image>
						</u-upload>
					</u-form-item>
					<u-form-item label="留言" prop="Leave" labelWidth=60>
						<u--textarea v-model="FormData.Leave" placeholder="请输入留言信息" count height=120></u--textarea>
					</u-form-item>
				</u--form>
			</view>
		</view>
		<view class="addfoot">
			<view style="margin: 20rpx 0 0 40rpx">
				<u-checkbox-group @change="checkboxChange">
					<view>
						<u-checkbox :checked="checked" shape="circle" activeColor="#0782C9"></u-checkbox>
					</view>
					<view style="font-size: 28rpx;">
						我已阅读同意
						<text style="color: #0782C9;">《隐私服务协议》</text>
					</view>
				</u-checkbox-group>
			</view>
			<view class="addBtn" @click="submit">提交申请</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				showCity: false,
				lodingselect: false,
				checked: false,
				columns: [
					[{
							label: '陪诊师',
							id: 1
						},
						{
							label: '陪护师',
							id: 2
						},
						{
							label: '代办代取',
							id: 3
						},
					]
				],
				columnsCity: [
					['中国', '美国'],
					['深圳', '厦门', '上海', '拉萨']
				],
				columnData: [
					['深圳', '厦门', '上海', '拉萨'],
					['得州', '华盛顿', '纽约', '阿拉斯加']
				],
				FormData: {
					name: '',
					Leave: ''
				},
				fileList: [],
				rules: {
					occupation: [{
						type: 'string',
						required: true,
						message: '请选择职业',
						trigger: ['blur', 'change']
					}],
					name: [{
						type: 'string',
						required: true,
						message: '请填写姓名',
						trigger: ['blur', 'change']
					}],
					phoneNumber: [{
						type: 'string',
						required: true,
						message: '请填写手机号码',
						trigger: ['blur', 'change']
					}],
					wechatId: [{
						type: 'string',
						required: true,
						message: '请填写微信号',
						trigger: ['blur', 'change']
					}],
					cityId: [{
						type: 'string',
						required: true,
						message: '请选择城市',
						trigger: ['blur', 'change']
					}],
					district: [{
						type: 'string',
						required: true,
						message: '请填写所在地区',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		methods: {
			onNotify(type,msg) {
				this.$refs.uNotify.show({
					type: type,
					message: msg,
					duration: 1000 * 3
				})
			},
			submit() {
				console.log(this.FormData);
				this.$refs.FormData.validate().then(res => {
					this.onNotify('success','校验通过');
				}).catch(errors => {
                    this.onNotify('error','校验失败');
				})
			},
			confirm(e) {
				this.FormData.occupation = e.value[0].label;
				this.show = false;
			},
			confirmCity(e) {
				this.FormData.cityId = e.value[1];
				this.showCity = false;
			},
			changeHandler(e) {
				const {
					columnIndex,
					index,
					// 微信小程序无法将picker实例传出来，只能通过ref操作
					picker = this.$refs.uPicker
				} = e
				if (columnIndex === 0) {
					this.lodingselect = true
					// 模拟网络请求
					uni.$u.sleep(1500).then(() => {
						picker.setColumnValues(1, this.columnData[index])
						this.lodingselect = false
					})
				}
			},
			afterRead(event) {
				let lists = [].concat(event.file)
				console.log(lists);
				this.fileList.push(lists[0].url);
			},
			checkboxChange() {
				this.checked = !this.checked;
				console.log(this.checked);
			}
		}
	}
</script>

<style lang="scss">
	body {
		background-color: $uni-bg-color-grey;
	}

	.addForm {
		padding: 20rpx;
		padding-bottom: 200rpx;
	}

	.formBox {
		background: #ffffff;
		border-radius: 10rpx;
		overflow: hidden;
		margin-bottom: 20rpx;
		box-shadow: 3rpx 3rpx 6rpx 0 #D3D0D0;
		padding: 0 20rpx;
	}

	.u-form-item__body__right__message.data-v-067e4733 {
		text-align: right;
	}

	.addfoot {
		position: fixed;
		bottom: 0;
		width: 100%;
		box-shadow: 0 -5rpx 10rpx #D3D0D0;
		background: #ffffff;
	}

	.addBtn {
		width: 90%;
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		background: linear-gradient(to left, $uni-aicloud, $uni-aicloud-gradation);
		color: #ffffff;
		font-size: 28rpx;
		border-radius: 80rpx;
		margin: 30rpx auto;

	}
</style>